package com.lin.controller;

import com.lin.pojo.Article;
import com.lin.service.ArticleService;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ClassName ArticleController
 * @Description 文章逻辑处理
 * @Author LinZePeng
 * @Date 2021/5/7 11:39
 * @Version 1.0
 */
@Controller
public class ArticleController {

	@Autowired
	private ArticleService articleService;


	/**
	 * @Description 返回所有文章
	 * @Param [model]
	 * @return java.lang.String
	 */
	@RequestMapping("/article")
	public String article(Model model) {
		List<Article> list = articleService.queryArticle();
		model.addAttribute("list",list);
		return "article";
	}

	/**
	 * @Description 具体展示页面
	 * @Param [ID, model]
	 * @return java.lang.String
	 */
	@RequestMapping("/article/{Id}")
	public String getArticle(@PathVariable String Id,Model model){
		Article article = articleService.queryByArtID(Id);
		model.addAttribute("art",article);
		return "addArticle";
	}

	/**
	 * @Description 添加博客内容
	 * @Param [article, httpServletRequest]
	 * @return java.lang.Boolean
	 */
	@RequestMapping("/article/add")
	@ResponseBody
	public Boolean getArticle(String article, HttpServletRequest httpServletRequest){
		return articleService.addArticle(article,httpServletRequest);
	}

}
